<?php
/**
 * Created by PhpStorm.
 * User: gesangdianzi
 * Date: 2017/12/30
 * Time: 14:35
 */

namespace frontend\controllers;


use common\models\Help;
use yii\web\Controller;
use yii\web\NotFoundHttpException;

class HelpController extends BaseController
{

    public function actionIndex(){
        $id = \Yii::$app->request->get("id");
        if(empty($id)){
            $row = Help::find()->orderBy("id desc")->one();
        }else{
            $row = Help::findOne($id);
        }
        if (empty($row)){
            throw new NotFoundHttpException();
        }
        $pre = Help::find()->select(['id',"title"])->where(['<','id',$row['id']])->orderBy("id desc")->asArray()->one();
        $next = Help::find()->select(['id',"title"])->where(['>','id',$row['id']])->asArray()->one();
        return $this->render("index",[
            'help' => $row,
            'pre' => $pre,
            'next' => $next,
        ]);
    }

    public function actionTest(){
        return $this->render("test");
    }
}